package com.paireach.bw.utils;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.paireach.bw.R;

/**
 * Created by ${cqc} on 2017/6/20.
 */

public class CustomProgressDialogUtil {

    private static Dialog mDialog;

    //    public  Dialog getInstance(Context context) {
    public CustomProgressDialogUtil(Context context) {
        if (mDialog == null) {
            AlertDialog.Builder mBuilder = new AlertDialog.Builder(context, R.style.full_screen_dialog);
            View view = LayoutInflater.from(context).inflate(R.layout.custom_dialog, null);
            mBuilder.setView(view);
            mBuilder.setCancelable(true);

            mDialog = mBuilder.create();
            mDialog.setCanceledOnTouchOutside(false);

            Window win = mDialog.getWindow();
            //显示对话框时，后面的Activity不变暗，可选操作。
            win.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            //获取对话框当前的参数值
            WindowManager.LayoutParams params = win.getAttributes();
            params.gravity = Gravity.CENTER;
            win.setAttributes(params);
        }
//        return mDialog;
    }

    public void showDialog() {
        if (!mDialog.isShowing()) {
            mDialog.show();
        }
    }

    public void dismissDialog() {
        if (mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }
}
